//
//  AMPLoginViewController.swift
//  LivingHelper
//
//  Created by Ampaw on 2017/9/12.
//  Copyright © 2017年 Ampaw. All rights reserved.
//

import UIKit

class AMPLoginViewController: AMPBaseViewController {

    // MARK: - 生命周期 方法
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 准备UI
        setUpUI()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        self.title = "登录"
    }
    
    override func backAction() {
        self.dismiss(animated: true, completion: nil)
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
    }
    
    // MARK: - 准备UI
    private func setUpUI() {
        self.loginView.loginViewDelegate = self
        self.view.addSubview(self.loginView)
        
        unowned let WS = self
        self.loginView.snp.makeConstraints { (make) -> Void in
            make.edges.equalTo(WS.view)
        }
    }
    
    // MARK: - 懒加载
    lazy var loginView: AMPLoginView = {
        let loginView = AMPLoginView()
        
        return loginView
    }()
}

// MARK: - 扩展
/// 扩展 AMPLoginViewController 实现 AMPLoginViewDelegate 协议
extension AMPLoginViewController: AMPLoginViewDelegate {
    func didLoginClick() {
        self.view.endEditing(true)
        let passport = self.loginView.passportTextField.text ?? ""
        let password = self.loginView.passwordTextField.text ?? ""
        print("登录账号 \(passport)")
        print("登录密码 \(password)")
    }
    
    func didRegisterClick() {
        self.view.endEditing(true)
        print("注册")
        let registerAuthVC = AMPRegisterAuthCodeViewController()
        self.navigationController?.pushViewController(registerAuthVC, animated: true)
    }
    
    func didForgetPwdCilck() {
        self.view.endEditing(true)
        print("忘记密码")
        let forgetPwdVC = AMPForgetPwdViewController()
        self.navigationController?.pushViewController(forgetPwdVC, animated: true)
    }
    
    func didOtherQQLoginClick() {
        self.view.endEditing(true)
        print("QQ 登陆")
    }
    
    func didOtherWeiXinLoginCilck() {
        self.view.endEditing(true)
        print("微信 登陆")
    }
    
    func didOtherWeiBoLoginClick() {
        self.view.endEditing(true)
        print("微博 登陆")
    }
}
